export const getSetting = () => {
	return new Promise((resolve, reject) =>{
		uni.getSetting({
			success(res){
				let authSetting = res.authSetting
				if (authSetting['scope.userLocation']) {
					getCurrentLocation().then(data=>{
						resolve(data)
					})
				}else if (authSetting['scope.userLocation'] === false) {
					console.log('拒绝1')
					uni.showModal({
					  title: '您未开启地理位置授权',
					  content: '请在系统设置中打开定位服务，以便定位当前位置，查询附近机构。',
					  success: (res) => {
						if (res.confirm) {
						  uni.openSetting()
						}
					  }
					})
				}else {
					uni.authorize({
					  scope: 'scope.userLocation',
					  success: () => {
						getCurrentLocation().then(data=>{
							resolve(data)
						})
					  },
					  fail: () => {
						  console.log('拒绝2')
						uni.showModal({
						  title: '您未开启地理位置授权',
						  content: '请在系统设置中打开定位服务，以便定位当前位置，查询附近机构。',
						  success: (res) => {
							if (res.confirm) {
							  uni.openSetting()
							}
						  }
						})
					  }
					})
				}
				console.log('dingwei',res)
			}
		})
	})
 
}
export const getCurrentLocation = () => {
	return new Promise((resolve, reject) =>{
		uni.getLocation({
		  type: 'gcj02',
		  success: function (res) {
			console.log('经纬度',res)
			resolve(res)
		  
		  },
		  fail: function(err) {
		    console.log(err);
			reject(err)
		    if(err.errMsg === 'getLocation:fail:auth denied') {
		      uni.showToast({
		        title: '拒绝授权',
		        icon: 'none'
		      })
		    } else if(err.errMsg === 'getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF' ||
		    err.errMsg === 'getLocation:fail system permission denied' ||
		    err.errMsg === 'getLocation:fail:system permission denied') {
		
		      uni.showModal({
		        title: '您未开启地理位置授权',
		        content: '请在系统设置中打开定位服务，以便定位当前位置，查询附近机构。',
		        showCancel: false
		      })
		    }
		  }
		})
	})
 
}